/**
 * 
 */
package com.quiz.activity.util;

import java.text.DecimalFormat;

import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.quiz.activity.R;
import com.quiz.model.Rank;

/**
 *
 * @author Brian Boyle
 * Apr 13, 2012
 */
public class QuizUtil {

    public static final String FLURRY_KEY = "C8479VDTMZCY7TTBQFPT";

    public static void buildScoreAndLivesBottomBar(int currentScore, int livesLeft, LinearLayout bottomBar, Activity context) {

        TextView currentScoreView = (TextView) context.findViewById(R.id.currentScore);
        currentScoreView.setText("Score " + QuizUtil.formatScore(currentScore));

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(25, 50);
        params.gravity = 10;
        params.leftMargin = 7;

        int x;
        for (x = 0; x < 3; x++) {
            ImageView lifeImageView = new ImageView(context);
            if (livesLeft == 0) {
                lifeImageView.setImageResource(R.drawable.gun_grey);
            } else {
                lifeImageView.setImageResource(R.drawable.gun);
                livesLeft--;
            }

            lifeImageView.setLayoutParams(params);
            lifeImageView.setTag("LifeImage");
            bottomBar.addView(lifeImageView);
        }

    }

    /**
     * Set the Sopranos mafia font on a TextView
     * @param textView
     */
    public static void setMafiaFont(TextView textView, float fontSize, AssetManager assets) {
        Typeface font = Typeface.createFromAsset(assets, "Mobsters.ttf");
        textView.setTypeface(font);
        textView.setTextSize(fontSize);
        textView.setTextColor(Color.RED);
    }

    /**
     * Format the score so that it puts commas in the correct place.
     * @param score The score value to format
     * @return The formatted score
     */
    public static String formatScore(double score) {
        DecimalFormat df = new DecimalFormat("#,###,###,###");
        return df.format(score);
    }

    public static int determineSectionNumber(String rank) {
        if (rank.equals(Rank.ASSOCIATE.getRankName())) {
            return 0;
        } else if (rank.equals(Rank.SOLDIER.getRankName())) {
            return 1;
        } else if (rank.equals(Rank.CAPO.getRankName())) {
            return 2;
        } else if (rank.equals(Rank.CONSIGLIERE.getRankName())) {
            return 3;
        } else if (rank.equals(Rank.UNDERBOSS.getRankName())) {
            return 4;
        } else if (rank.equals(Rank.BOSS.getRankName())) {
            return 5;
        }
        return 0;
    }
}
